<?php namespace Home\Controller;
use Common\Model\Member;
use Common\Model\User;
use Common\Model\Password;
//登录注册控制器
class MemberController extends CommonController{
	private $model;
	protected function __auto(){
		$this->model=new Member;
	}
    //载入登录页面
    public function index(){
    	$userModel=new User;
    	if(IS_AJAX){
    		if(!$userModel->store()){
    			$this->ajax(['status'=>FALSE,'message'=>$userModel->getError()]);
    		}else{
				$this->ajax(['status'=>TRUE,'message'=>'欢迎回来']);
    		}
		}
    	View::make();
	}
    //载入注册页面
	 public function reg(){
    	if(IS_AJAX){
    		if(!$this->model->store()){
    			$this->ajax(['status'=>FALSE,'message'=>$this->model->getError()]);
    		}else{
    			$this->ajax(['status'=>TRUE,'message'=>'注册成功']);
    		}
    	}
    	View::make();
	}
	//修改密码
	public function edit(){
		$passwordModel=new Password;
	   	if(IS_POST){
	   		if(!$passwordModel->store()) {
	   			View::error($passwordModel->getError());
			}else{
				session_unset();
				session_destroy();
				View::success('修改成功，请重新登录',U('Member/index'));
			}		
	   }
	}
	//显示验证码
	public function code(){
		Code::num(1)->make();
	}
	//退出登录
	public function del(){
		session_unset();
		session_destroy();
		go(U('Index/index'));
	}
}
?>